package com.example.demo.controller;


import Mapper.DateRecordMapper;
import com.example.demo.Service.DateService;
import com.example.demo.common.DeepSeekAnswer;
import entity.CDate;
import entity.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@RestController
public class DateRecordController {

    @Autowired
    private DateService service;

    @Autowired
    private DateRecordMapper mapper;

    @GetMapping("/check")
    public String check(@RequestParam("info") String info) throws Exception{
        String result =  new DeepSeekAnswer().getAnswer(info);
        return result;
    }

    @PostMapping("/daterecord")
    public String saveOrUpdateEmotion(@RequestBody CDate request) {
        Long userId = request.getUserId();
        LocalDate date = LocalDate.parse(request.getDate());
        String emotion = request.getEmotion();
        service.saveOrUpdateEmotionRecord(userId, date, emotion);
        return "Emotion record saved/updated successfully";
    }

    @PostMapping("/getdaterecord")
    public String getDateRecord(@RequestBody Date date) {

        System.out.println("获取"+date.getUser_id()+"号用户的"+date.getDate()+"情绪记录");
        return mapper.getDateRecord(date.getUser_id(), date.getDate());
    }
}